/* GUI CONVERTED from rcrp15.p (converter v1.75) Sat Aug 12 23:00:23 2000 */
/* rcrp15.p - SHIP SCHEDULE TO SHIP SCHEDULE VARIANCE REPORT            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*V8:ConvertMode=FullGUIReport                                          */
/* REVISION: 9.1   CREATED       : 10/13/99     BY: *N004* Steve Nugent */
/* REVISION: 9.1   LAST MODIFIED: 03/24/00      BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1   LAST MODIFIED: 08/12/00      BY: *N0KP* myb              */


/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

          {mfdtitle.i}

/* **************** Begin Translatable Strings Definitions **************** */

         &SCOPED-DEFINE rcrp15_p_1 "Variance % "
         /* MaxLen:18 Comment: Variance percentage. */

         &SCOPED-DEFINE rcrp15_p_2 "ABC Class"
         /* MaxLen:20 Comment: Relates to the ABC Class field in the Item
                               Master. This class designates the importance
                               of an item. */

         &SCOPED-DEFINE rcrp15_p_3 "Current Release ID"
         /* MaxLen:18 Comment: Current Release identification number. */

         &SCOPED-DEFINE rcrp15_p_4 "Previous Release ID"
         /* MaxLen:18 Comment: Previous Release identification number. */

         &SCOPED-DEFINE rcrp15_p_5 "Qty Diff"
         /* MaxLen:12 Comment: Quantity Difference */

         &SCOPED-DEFINE rcrp15_p_6 "Cum Qty Diff"
         /* MaxLen:12 Comment: Cumulative Quantity Difference */

         &SCOPED-DEFINE rcrp15_p_7 "Order"
         /* MaxLen:18 Comment: The scheduled sales order. */

         &SCOPED-DEFINE rcrp15_p_8 "Ship-From"
         /* MaxLen:18 Comment: The schedule ship-from. */

         &SCOPED-DEFINE rcrp15_p_9 "Ship-From!Ship-To"
         /* MaxLen:9 Comment: The schedule ship-to. */

         &SCOPED-DEFINE rcrp15_p_10 "Order!Line"
         /* MaxLen:8 Comment: The sales order and line associated with
                              the schedule */

         &SCOPED-DEFINE rcrp15_p_11 "Curr Discrete Qty!Prev Discrete Qty"
         /* MaxLen:17 Comment: The previous discrete schedule quantities as
                             compared to the current discrete schedule
                             quantities. */

         &SCOPED-DEFINE rcrp15_p_12 "Current Cum Qty!Previous Cum Qty"
         /* MaxLen:16 Comment: The previous cumulative schedule quantities as
                             compared to the current cumulative schedule
                             quantities. */

         &SCOPED-DEFINE rcrp15_p_13 "Current Release ID!Previous Release ID"
         /* MaxLen:16 Comment: The current and previous release ID of the
                               reported schedule */


/* ***************** End Translatable Strings Definitions ******************* */


         define variable in_rlid_one   like sch_rlse_id no-undo.
         define variable in_rlid_two   like sch_rlse_id no-undo.
         define variable wk_curr_rlid  like sch_rlse_id no-undo.
         define variable wk_prev_rlid  like sch_rlse_id no-undo.
         define variable diff_qty      like ld_qty_oh label
                                        {&rcrp15_p_5} no-undo.
         define variable cum_diff_qty  like ld_qty_oh label
                                        {&rcrp15_p_6} no-undo.
         define variable so_from       like so_nbr no-undo.
         define variable so_to         like so_nbr no-undo.
         define variable var_variance  as  decimal
            format "99" label {&rcrp15_p_1} no-undo.
         define variable wk_percent_qty as decimal format "999.999" no-undo.
         define variable wk_percent_cum as decimal format "999.999" no-undo.
         define variable wk_variance   as decimal format ".99" no-undo.
         define variable var_abc_class as  character
            format "x(1)" label {&rcrp15_p_2} no-undo.
         define variable wk_del_flag   like mfc_logical no-undo.
         define variable wk_delta      like schd_discr_qty no-undo.
         define variable wk_upper_lmt  like schd_discr_qty no-undo.
         define variable wk_lower_lmt  like schd_discr_qty no-undo.
         define variable part_from     like sod_part no-undo.
         define variable part_to       like sod_part no-undo.
         define variable shipto_from   like so_ship no-undo.
         define variable shipto_to     like so_ship no-undo.
         define variable shipfrom_from like scx_shipfrom no-undo.
         define variable shipfrom_to   like scx_shipfrom no-undo.
         define variable curr_schd_discr_qty
                                       like schd_discr_qty no-undo.
         define variable prev_schd_discr_qty
                                       like schd_discr_qty no-undo.



         define temp-table ship_schd_day no-undo
                field ssd_nbr       like so_nbr
                field ssd_line      like schd_line
                field ssd_date      like schd_date
                field ssd_part      like sod_part
                field ssd_desc      like pt_desc1
                field ssd_curr_rlid like schd_rlse_id label {&rcrp15_p_3}
                field ssd_prev_rlid like schd_rlse_id label {&rcrp15_p_4}
                field ssd_curr_flag as logical
                field ssd_prev_flag as logical
                field ssd_curr_qty  like schd_discr_qty
                field ssd_prev_qty  like schd_discr_qty
                field ssd_curr_cum  like schd_cum_qty
                field ssd_prev_cum  like schd_cum_qty
                field ssd_fc_qual   like schd_fc_qual
                field ssd_interval  like schd_interval
                field ssd_cum_qty   like schd_cum_qty
                field ssd_pct_qty   as decimal
                                    format "ZZZ99"
                                    label {&rcrp15_p_1}
                field ssd_pct_cum   as decimal
                                    format "ZZZ99"
                                    label {&rcrp15_p_1}
                field ssd_shipfrom  like scx_shipfrom
                field ssd_shipto    like scx_shipto
                index ssd_index1    is unique primary
                                    ssd_nbr
                                    ssd_line
                                    ssd_date.

        
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
           
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
shipfrom_from        colon 22 label {&rcrp15_p_8}
           shipfrom_to          colon 50 label {t001.i}
           shipto_from          colon 22
           shipto_to            colon 50 label {t001.i}
           part_from            colon 22
           part_to              colon 50 label {t001.i}
           so_from              colon 22 label {&rcrp15_p_7}
           so_to                colon 50 label {t001.i}
           skip (1)
           var_variance         colon 22
           var_abc_class        colon 22
           skip (1)
           in_rlid_one          colon 22 label {&rcrp15_p_3}
           in_rlid_two          colon 22 label {&rcrp15_p_4}
           skip (1)
         SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



        /* SET EXTERNAL LABELS */
        setFrameLabels(frame a:handle).

         {wbrp01.i}

         
/*GUI*/ {mfguirpa.i true  "printer" 132 }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:

            display
               var_variance with frame a.

            if shipfrom_to = hi_char then shipfrom_to = "".
            if so_to   = hi_char then so_to = "".
            if part_to = hi_char then part_to = "".
            if shipto_to = hi_char then shipto_to = "".

            if c-application-mode <> 'WEB':U then
               
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:



            {wbrp06.i &command = update
                      &fields = "shipfrom_from shipfrom_to shipto_from
                                 shipto_to part_from part_to so_from so_to
                                 var_variance var_abc_class
                                 in_rlid_one in_rlid_two "
                      &frm = "a"}

             if (c-application-mode <> 'WEB':U)  or
             (c-application-mode = 'WEB':U and
             (c-web-request begins 'DATA':U))
             then do:
                   bcdparm = "".
                   {mfquoter.i shipfrom_from}
                   {mfquoter.i shipfrom_to }
                   {mfquoter.i shipto_from}
                   {mfquoter.i shipto_to }
                   {mfquoter.i part_from   }
                   {mfquoter.i part_to     }
                   {mfquoter.i so_from     }
                   {mfquoter.i so_to       }
                   {mfquoter.i var_variance }
                   {mfquoter.i var_abc_class }
                   {mfquoter.i in_rlid_one }
                   {mfquoter.i in_rlid_two }

                   if shipfrom_to = "" then shipfrom_to = hi_char.
                   if so_to = "" then so_to = hi_char.
                   if part_to = "" then part_to = hi_char.
                   if shipto_to = "" then shipto_to = hi_char.

             end.  /* do */

             /* SELECT PRINTER */
             
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i  "printer" 132}
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:



             {mfphead2.i}

             /* Main Loop */
             assign
                wk_variance = var_variance / 100.

             for each so_mstr where
                       (so_nbr >= so_from and so_nbr <= so_to) and
                       (so_ship >= shipto_from and so_ship <= shipto_to)
                       no-lock,
                       each sod_det where
                       so_nbr = sod_nbr  and
                       sod_curr_rlse_id[2] <> ''  and
                       (sod_part >= part_from and sod_part <= part_to) and
                       (sod_site >= shipfrom_from and sod_site <= shipfrom_to)
                       no-lock,
                       each pt_mstr where
                       pt_part = sod_part no-lock:

                 if var_abc_class <> "" then
                    if pt_abc <> var_abc_class then
                    next.

                if (in_rlid_one = "" or in_rlid_two = "" )
                then do:
                    find last sch_mstr where sch_rlse_id = sod_curr_rlse_id[2]
                             and sch_type = 2
                             and sch_nbr = so_nbr
                             and sch_line = sod_line
                             use-index sch_cr_date
                             no-lock no-error.

                     if not available sch_mstr then
                     next.
                     else
                     wk_curr_rlid = sch_rlse_id.

                     find prev sch_mstr where sch_type = 2
                                        and   sch_nbr = so_nbr
                                        and   sch_line = sod_line
                                        use-index sch_cr_date
                                        no-lock no-error.

                     if not available sch_mstr then
                     next.
                     else
                     wk_prev_rlid = sch_rlse_id.

                 end. /* if then do */
                 else do:
                    find last sch_mstr where sch_rlse_id = in_rlid_one
                             and sch_type = 2
                             and sch_nbr = so_nbr
                             and sch_line = sod_line
                             use-index sch_cr_date
                             no-lock no-error.

                     if not available sch_mstr then
                     next.
                     else
                     wk_curr_rlid = sch_rlse_id.

                     find last sch_mstr where sch_rlse_id = in_rlid_two
                                        and   sch_type = 2
                                        and   sch_nbr = so_nbr
                                        and   sch_line = sod_line
                                        use-index sch_cr_date
                                        no-lock no-error.

                     if not available sch_mstr then
                     next.
                     else
                     wk_prev_rlid = sch_rlse_id.

                 end. /* else do */
                 find last sch_mstr where sch_rlse_id = wk_curr_rlid
                         and sch_type = 2
                         and sch_nbr = so_nbr
                         and sch_line = sod_line
                         use-index sch_cr_date
                         no-lock no-error.
                 assign curr_schd_discr_qty = 0.

                 for each schd_det
                         where sch_type = schd_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         no-lock
                         break
                         by schd_type
                         by schd_nbr
                         by schd_line
                         by schd_rlse_id
                         by schd_date:

                         assign curr_schd_discr_qty =
                            curr_schd_discr_qty + schd_discr_qty.

                         if last-of (schd_date)
                         then do:
                             for first scx_ref where
                                       scx_type = 1 and
                                       scx_order = schd_nbr and
                                       scx_line  = schd_line no-lock:
                             end.

                             create ship_schd_day.
                             assign
                             ssd_nbr       = schd_nbr
                             ssd_line      = schd_line
                             ssd_date      = schd_date
                             ssd_part      = sod_part
                             ssd_desc      = pt_desc1
                             ssd_curr_rlid = wk_curr_rlid
                             ssd_prev_rlid = wk_prev_rlid
                             ssd_curr_flag = yes
                             ssd_prev_flag = no
                             ssd_curr_qty  = curr_schd_discr_qty
                             ssd_prev_qty  = 0
                             ssd_curr_cum   = schd_cum_qty
                             ssd_fc_qual   = schd_fc_qual
                             ssd_interval  = schd_interval
                             ssd_cum_qty   = schd_cum_qty
                             ssd_shipfrom  = scx_shipfrom
                             ssd_shipto    = scx_shipto.
                             assign curr_schd_discr_qty = 0.
                         end. /* do */

                 end. /* for each schd_det */
                 find last sch_mstr where sch_rlse_id = wk_prev_rlid
                                    and   sch_type = 2
                                    and   sch_nbr = so_nbr
                                    and   sch_line = sod_line
                                    use-index sch_cr_date
                                    no-lock no-error.

                 if available sch_mstr
                 then do:
                    assign prev_schd_discr_qty = 0.

                    for each schd_det
                         where sch_type = schd_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         no-lock
                         break
                         by schd_type
                         by schd_nbr
                         by schd_line
                         by schd_rlse_id
                         by schd_date:

                         assign prev_schd_discr_qty =
                             prev_schd_discr_qty + schd_discr.

                         if last-of (schd_date)
                         then do:
                             for first ship_schd_day
                                where ssd_nbr       = schd_nbr
                                and   ssd_line      = schd_line
                                and   ssd_date      = schd_date
                                exclusive-lock:
                             end. /* for first */

                             if available ship_schd_day
                             then do:
                                ssd_prev_flag       = yes.
                                ssd_prev_qty        = prev_schd_discr_qty.
                                ssd_prev_cum        = schd_cum_qty.
                             end. /* do */
                             else do:
                                 if prev_schd_discr_qty <> 0
                                 then do:

                                     for first scx_ref where
                                               scx_type = 1  and
                                               scx_order = schd_nbr  and
                                               scx_line = schd_line no-lock:
                                     end.

                                     create ship_schd_day.
                                     assign
                                     ssd_nbr       = schd_nbr
                                     ssd_line      = schd_line
                                     ssd_date      = schd_date
                                     ssd_part      = sod_part
                                     ssd_desc      = pt_desc1
                                     ssd_curr_rlid = wk_curr_rlid
                                     ssd_curr_qty  = 0
                                     ssd_prev_rlid = wk_prev_rlid
                                     ssd_curr_cum  = 0
                                     ssd_curr_flag = no
                                     ssd_prev_flag = yes
                                     ssd_prev_cum  = schd_cum_qty
                                     ssd_prev_qty  = prev_schd_discr_qty
                                     ssd_fc_qual   = schd_fc_qual
                                     ssd_interval  = schd_interval
                                     ssd_cum_qty   = schd_cum_qty
                                     ssd_shipfrom  = scx_shipfrom
                                     ssd_shipto    = scx_shipto.
                                 end. /* do */
                             end. /* else do */
                          assign prev_schd_discr_qty = 0.
                         end. /* do if last of */
                    end. /* for each schd_det */
                end. /* if available */

                for each ship_schd_day exclusive-lock:

                    wk_del_flag = no.

                    if ssd_curr_qty = ssd_prev_qty then
                        wk_del_flag = yes.
                    if not ssd_prev_flag
                    or not ssd_curr_flag  then
                        wk_del_flag = yes.

                    if wk_del_flag = no
                    then do:
                        assign
                           wk_delta = ssd_curr_qty * wk_variance
                           wk_upper_lmt = ssd_curr_qty + wk_delta
                           wk_lower_lmt = ssd_curr_qty - wk_delta.

                        if  ssd_prev_qty < wk_upper_lmt
                        and ssd_prev_qty > wk_lower_lmt
                            then wk_del_flag = yes.
                    end. /* do */

                    if wk_del_flag then
                        delete ship_schd_day.
                    else do:

                      assign
                        diff_qty = ssd_curr_qty - ssd_prev_qty
                        cum_diff_qty = ssd_curr_cum - ssd_prev_cum.

                        if diff_qty > 0 then
                            wk_percent_qty = diff_qty / ssd_curr_qty.
                        else
                          assign
                            diff_qty = diff_qty * -1
                            wk_percent_qty = diff_qty / ssd_curr_qty.

                        if ssd_curr_qty = 0 then
                            wk_percent_qty = 1.

                        if cum_diff_qty > 0 then
                            wk_percent_cum = cum_diff_qty / ssd_curr_cum.
                        else
                         assign
                            cum_diff_qty = cum_diff_qty * -1
                            wk_percent_cum = cum_diff_qty / ssd_curr_cum.

                       if ssd_curr_cum = 0 then
                            wk_percent_cum = 1.

                        assign
                           ssd_pct_qty = wk_percent_qty * 100
                           ssd_pct_cum = wk_percent_cum * 100.
                    end. /* do */
                end. /* for each */

                FORM /*GUI*/ 
                with STREAM-IO /*GUI*/  frame ssdhead down width 132 no-box.

                /* SET EXTERNAL LABELS */
                setFrameLabels(frame ssdhead:handle).

                FORM /*GUI*/ 
                with STREAM-IO /*GUI*/  frame ssddet down width 132 no-box.

                /* SET EXTERNAL LABELS */
                setFrameLabels(frame ssddet:handle).

                clear frame ssdhead all no-pause.
                clear frame ssddet all no-pause.

                for each ship_schd_day
                exclusive-lock
                break
                by ssd_shipfrom
                by ssd_shipto
                by ssd_nbr
                by ssd_line
                by ssd_date:
                    if first-of (ssd_line) then do:
                        display ssd_shipfrom column-label {&rcrp15_p_9}
                                ssd_nbr column-label {&rcrp15_p_10}
                                ssd_part
                                ssd_desc
                                ssd_curr_rlid column-label {&rcrp15_p_13}
                                with frame ssdhead STREAM-IO /*GUI*/ .

                                down 1 with frame ssdhead.

                        display ssd_shipto @ ssd_shipfrom
                                ssd_line   @ ssd_nbr
                                ssd_prev_rlid @ ssd_curr_rlid
                                with frame ssdhead STREAM-IO /*GUI*/ .

                                down 2 with frame ssdhead.
                    end.
                    assign
                        diff_qty = ssd_curr_qty - ssd_prev_qty
                        cum_diff_qty = ssd_curr_cum - ssd_prev_cum.
                    display
                            space(10)
                            ssd_date
                            ssd_curr_qty column-label {&rcrp15_p_11}
                            diff_qty when (diff_qty <> 0)
                            ssd_pct_qty  when (ssd_pct_qty <> 0)
                            space(8)
                            ssd_curr_cum column-label {&rcrp15_p_12}
                            cum_diff_qty  when (cum_diff_qty <>0)
                            ssd_pct_cum when (ssd_pct_cum <> 0)
                            with frame ssddet STREAM-IO /*GUI*/ .

                            down 1 with frame ssddet.

                    display
                            ssd_prev_qty @ ssd_curr_qty
                            ssd_prev_cum @ ssd_curr_cum
                            with frame ssddet STREAM-IO /*GUI*/ .

                            down 2 with frame ssddet.

                    delete ship_schd_day.
                end. /* for each */
             end. /* for each so_mstr */

             /* REPORT TRAILER */
             
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

         end.  /* repeat */

         {wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" shipfrom_from shipfrom_to shipto_from shipto_to part_from part_to so_from so_to var_variance var_abc_class in_rlid_one in_rlid_two "} /*Drive the Report*/
